const nodemailer = require("nodemailer");


export interface UserConfig {
	user: string;
	pass: string;
}

export interface SendMailConfig {
	to: string;
	title: string;
	subject?: string;
	text: string;
	flag?: any;
}
export async function sendMail(sendMailConfig: SendMailConfig, userConfig: UserConfig) {
	const transporter = nodemailer.createTransport({
		host: "smtp.qq.com",
		port: 465,
		secure: true,
		auth: { ...userConfig }
	});
	transporter.sendMail(
		{
			from: `Anonymous <${userConfig.user}>`,
			to: `${sendMailConfig.to}`,
			subject: `${sendMailConfig.subject}`,
			text: `${sendMailConfig.text}`,
			title: `${sendMailConfig.title}`,
		},
		(err: NodeJS.ErrnoException) => {
			if (err) {
				console.log(err);
			}
			console.log(`mail has been sent to user successfully => ${sendMailConfig.to}`);
		}
	);
}
